package com.serverImpl;

import com.beans.Question;
import com.mapper.QuestionMapper;
import com.server.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuestionServiceImpl implements QuestionService {
    @Autowired
    private QuestionMapper questionMapper;

    @Override
    public Question getQuestionById(int questionID) {
        return questionMapper.selectById(questionID);
    }

    @Override
    public List<Question> getAllQuestions() {
        return questionMapper.selectList(null);
    }

    @Override
    public void addQuestion(Question question) {
        questionMapper.insert(question);
    }

    @Override
    public int updateSelective(Question question) {
        questionMapper.updateSelective(question);
        return 0;
    }

    @Override
    public void deleteQuestion(int questionID) {
        questionMapper.deleteById(questionID);
    }

    @Override
    public boolean compareAnswers(int questionID, String selectedOption) {
        int count = questionMapper.compareAnswers(questionID, selectedOption);
        return count > 0;
    }
}
